package com.letv.whatslive.model.convert;

import com.letv.whatslive.common.utils.ObjectUtils;
import com.letv.whatslive.model.FeedBack;
import com.letv.whatslive.model.utils.Constant;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created by gaoshan on 15-8-31.
 */
public class FeedBackConvert {

    public static DBObject castFeedBackToDBObject(FeedBack feedBack) {
        DBObject dbo = new BasicDBObject();
        if (feedBack.getId() != null) {
            dbo.put("_id", feedBack.getId());
        }
        dbo.put("imei", ObjUtils.ifNull(feedBack.getImei(), ""));
        dbo.put("ip",ObjUtils.ifNull(feedBack.getIp(),""));
        dbo.put("userId", ObjUtils.toLong(feedBack.getUserId()));
        dbo.put("programId",ObjUtils.toString(feedBack.getProgramId()));
        dbo.put("phone",ObjUtils.toString(feedBack.getPhone(),""));
        dbo.put("lastGetPlayUrlTime", ObjUtils.toLong(feedBack.getLastGetPlayUrlTime()));
        dbo.put("lastPlayTime", ObjUtils.toLong(feedBack.getLastPlayTime()));
        dbo.put("lastTotalPlayTime", ObjUtils.toLong(feedBack.getLastTotalPlayTime(),0l));
        dbo.put("feedBack", ObjUtils.ifNull(feedBack.getFeedback(), ""));
        dbo.put("createTime", ObjUtils.toLong(System.currentTimeMillis()));
        dbo.put("network", ObjUtils.ifNull(feedBack.getNetwork(), ""));
        dbo.put("from", ObjUtils.toInteger(feedBack.getFrom()));
        dbo.put("feedbackContent",ObjUtils.toString(feedBack.getFeedbackContent()));
        dbo.put("appId",ObjUtils.toString(feedBack.getAppId()));
        return dbo;
    }

    public static FeedBack castDBObjectToFeedBack(DBObject dbObject){
        FeedBack feedBack=new FeedBack();
        if(dbObject!=null){
            feedBack.setId(ObjectUtils.toLong(dbObject.get("_id")));
            feedBack.setProgramId(ObjectUtils.toString(dbObject.get("programId")));
            feedBack.setUserId(ObjectUtils.toLong(dbObject.get("userId")));
            feedBack.setImei(ObjectUtils.toString(dbObject.get("imei")));
            feedBack.setPhone(ObjectUtils.toString(dbObject.get("phone")));
            feedBack.setFeedback(ObjectUtils.toString(dbObject.get("feedBack")));
            feedBack.setLastGetPlayUrlTime(ObjectUtils.toLong(dbObject.get("lastGetPlayUrlTime")));
            feedBack.setLastPlayTime(ObjectUtils.toLong(dbObject.get("lastPlayTime")));
            feedBack.setLastTotalPlayTime(ObjectUtils.toLong(dbObject.get("lastTotalPlayTime")));
            feedBack.setIp(ObjectUtils.toString(dbObject.get("ip")));
            feedBack.setNetwork(ObjectUtils.toString(dbObject.get("network")));
            feedBack.setCreateTime(ObjectUtils.toLong(dbObject.get("createTime")));
            feedBack.setFeedbackContent(ObjectUtils.toString(dbObject.get("feedbackContent")));
            feedBack.setAppId(ObjectUtils.toString(dbObject.get("appId")));
            return feedBack;
        }else{
            return null;
        }
    }
}
